package com.example.a1.fannong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a1.fannong.R;
import com.example.a1.fannong.core.app.BaseListAdapter;
import com.example.a1.fannong.model.AddressEntity;
import com.example.a1.fannong.ui.shoppingcart.AddressActivity;

import cn.personal.library.viewinject.FindViewById;
import cn.personal.library.viewinject.ViewInjecter;

/**
 * Created by 1 on 2017/10/19.
 */

public class AddressAapter extends BaseListAdapter<AddressEntity>{

    public AddressAapter(Context context) {
        super(context);
    }

    @Override
    public View newView(LayoutInflater inflater, int position, AddressEntity item, ViewGroup parent) {
        View view = View.inflate(getContext(), R.layout.item_address, null);
        ViewHolder viewHolder = new ViewHolder();
        ViewInjecter.inject(viewHolder, view);
        view.setTag(viewHolder);
        return view;
    }

    @Override
    public void bindView(View view, int position, AddressEntity item) {
        final ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.nameTv.setText(item.getName());
        viewHolder.addressTv.setText(item.getAddress());
        viewHolder.detailedAddressTv.setText(item.getDetailed_address());
        viewHolder.telTv.setText(item.getTel());
        viewHolder.mSelectRb.setChecked(item.getIs_default());

        viewHolder.editLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddressActivity.startActivity(getContext(),"1");
            }
        });
    }
    public static class ViewHolder {
        @FindViewById(R.id.address_name_tv)
        public TextView nameTv;
        @FindViewById(R.id.address_tv)
        public TextView addressTv;
        @FindViewById(R.id.detailed_address_tv)
        public TextView detailedAddressTv;
        @FindViewById(R.id.tel_tv)
        public TextView telTv;
        @FindViewById(R.id.default_tv)
        public TextView defaultTv;
        @FindViewById(R.id.edit_layout)
        public LinearLayout editLayout;
        @FindViewById(R.id.select_rb)
        public CheckBox mSelectRb;
    }

}
